package com.gxa.saas.admin.controller;


import com.gxa.saas.admin.entiry.GBGoodsVO;
import com.gxa.saas.admin.entiry.Menu;
import com.gxa.saas.admin.entiry.SGVO;
import com.gxa.saas.admin.service.GBGoodsService;
import com.gxa.saas.core.common.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api("商品管理模块")
@RestController
@RequestMapping("/GBGoods")
@Component
public class GBGoodsController {


    @Autowired
    @Qualifier("MyGBJmsTemplate")
    private JmsMessagingTemplate jmsMessagingTemplate=null;
    public static final String hot_commodity="HotCommodity";

    @Autowired
    private GBGoodsService gbGoodsService;


    @ApiOperation("全部商品接口")
    @GetMapping("/Goods")
    public JsonResult getAll(){
        JsonResult js=new JsonResult();
        js.setCode("200");
        js.setMsg("查询成功");
        List<GBGoodsVO> list = gbGoodsService.queryGoods();
        js.setData(list);
        return js;
    }
    @ApiOperation("商品分类接口")
    @GetMapping("/classify")
    public JsonResult getclassify(){
        JsonResult js=new JsonResult();
        js.setCode("200");
        js.setMsg("查询成功");
        List<Menu> menus = gbGoodsService.queryMenu();
        js.setData(menus);
        return js;
    }
    @ApiOperation("商品条件查询接口")
    @ResponseBody
    @PostMapping("/queryGoods")
    public JsonResult queryGoods(SGVO sgvo){   //没有实现一二级菜单的查询
        JsonResult js=new JsonResult();
        js.setCode("200");
        js.setMsg("查询成功");
        List<GBGoodsVO> list = gbGoodsService.queryGoodsByCondition(sgvo);
        js.setData(list);
        return js;
    }
    @ApiOperation("商品推荐接口")
    @ResponseBody
    @PostMapping("/recommend")
    public JsonResult recommend(Integer id){  //MQ通信队列 未实现




        JsonResult js=new JsonResult();
        js.setCode("200");
        js.setMsg("推荐成功");
        js.setData(id);
        return js;
    }
    @ApiOperation("商品下架接口")
    @ResponseBody
    @PostMapping("/goodsOff")
    public JsonResult goodsOff(Integer id){   //
        JsonResult js=new JsonResult();
        if(gbGoodsService.goodsDown(id)){
            js.setCode("200");
            js.setMsg("下架成功");
        }else {
            js.setCode("601");
            js.setMsg("下架失败");
        }
        return js;
    }
    @ApiOperation("商品删除接口")
    @ResponseBody
    @PostMapping("/goodsDelete")
    public JsonResult goodsDelete(Integer id){
        JsonResult js=new JsonResult();
        if(gbGoodsService.goodsDelete(id)){
            js.setCode("200");
            js.setMsg("删除成功");
        }else {
            js.setCode("602");
            js.setMsg("删除失败");
        }
        return js;
    }



//    审核商品相关接口

    @ApiOperation("展示审核商品接口")
    @GetMapping("/auditGoods")
    public JsonResult auditGoods(){
        JsonResult js=new JsonResult();
        js.setCode("200");
        js.setMsg("查询成功");
        List<GBGoodsVO> list = gbGoodsService.auditGoods();
        js.setData(list);
        return js;
    }

    @ApiOperation("审核条件查询商品接口")
    @PostMapping("/auditGoodsCon")
    @ResponseBody
    public JsonResult auditGoodsByCon(SGVO sgvo){
        JsonResult js=new JsonResult();
        js.setCode("200");
        js.setMsg("审核完成");
        List<GBGoodsVO> list = gbGoodsService.auditGoodsByCon(sgvo);
        js.setData(list);
        return js;
    }

    @ApiOperation("审核商品接口")
    @PostMapping("/updateGoods")
    @ResponseBody
    public JsonResult updateGoods(Integer id,Integer Status){
        JsonResult js=new JsonResult();
        Integer flag = gbGoodsService.updateGoods(id, Status);
        if(flag>0){
            js.setCode("200");
            js.setMsg("审核完成");
        }else {
            js.setCode("202");
            js.setMsg("审核失败,商品id有误（可能已经审核过了）");
        }
        return js;
    }
}
